import 'package:flutter/material.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/vo/good_item_vo.dart';
import 'package:get/get.dart';

/// 精选好物商品列表
class CullingGoodsArr extends StatelessWidget {

  final List<GoodItem> goodsArr;
  CullingGoodsArr({ required this.goodsArr });

  @override
  Widget build(BuildContext context) {
    // return goodsArr.length <= 0 ? Column(
    //   mainAxisAlignment: MainAxisAlignment.center,
    //   children: [
    //     SizedBox(height: 32.h),
    //     Image.asset(
    //       'assets/icons/goods_list_def.png',
    //       width: 221.w,
    //       height: 118.h,
    //     ),
    //     Text(
    //       '暂无相关数据哦~',
    //       style: TextStyle(
    //         color: textSubtitleColor,
    //         fontSize: 14.sp
    //       ),
    //     )
    //   ],
    // ) : ListView.builder(
    //   itemCount: goodsArr.length,
    //   shrinkWrap: true,
    //   physics: NeverScrollableScrollPhysics(),
    //   itemBuilder: (context, index) {
    //     print('hhahahha$index');
    //     GoodItem item = goodsArr[index];
    //     return Container(
    //       padding: EdgeInsets.symmetric(horizontal: 16.w),
    //       margin: EdgeInsets.only(bottom: 12.h),
    //       child: InkWellUtil.shakeProofInkWell(Container(
    //         padding: EdgeInsets.only(left: 12.w, right: 20.w, top: 16.h, bottom: 16.h),
    //         decoration: BoxDecoration(
    //           color: bgWhiteColor,
    //           borderRadius: BorderRadius.circular(5.w)
    //         ),
    //         child: Row(
    //           children: [
    //             NetworkImageUtil(
    //               url: item.thumbnail ?? '', 
    //               width: 97.w, 
    //               height: 97.w,
    //               borderRadius: 5.w,
    //             ),
    //             SizedBox(width: 12.h),
    //             Expanded(child: Container(
    //               constraints: BoxConstraints(
    //                 minHeight: 97.w
    //               ),
    //               child: Column(
    //                 crossAxisAlignment: CrossAxisAlignment.start,
    //                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                 children: [
    //                   Text(
    //                     item.title ?? '',
    //                     overflow: TextOverflow.ellipsis,
    //                     maxLines: 2,
    //                     style: TextStyle(
    //                       color: textBlackColor,
    //                       fontSize: 14.sp
    //                     ),
    //                   ),
    //                   Text.rich(
    //                     TextSpan(
    //                       text: '¥',
    //                       style: TextStyle(
    //                         color: mainTextColor,
    //                         fontWeight: FontWeight.bold,
    //                         fontSize: 14.sp
    //                       ),
    //                       children: [
    //                         TextSpan(
    //                           text: item.price,
    //                           style: TextStyle(
    //                             color: mainTextColor,
    //                             fontWeight: FontWeight.bold,
    //                             fontSize: 18.sp
    //                           ),
    //                         )
    //                       ]
    //                     )
    //                   ),
    //                   Row(
    //                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                     crossAxisAlignment: CrossAxisAlignment.end,
    //                     children: [
    //                       Container(
    //                         padding: EdgeInsets.only(bottom: 3.h),
    //                         child: Text(
    //                           '+${item.integral}积分',
    //                           overflow: TextOverflow.ellipsis,
    //                           style: TextStyle(
    //                             color: mainTextColor,
    //                             fontSize: 12.sp
    //                           ),
    //                         ),
    //                       ),
    //                       Container(
    //                         width: 56.w,
    //                         height: 34.h,
    //                         child: ButtonUtil(
    //                           text: '去下单', 
    //                           fontSize: 12.sp, 
    //                           borderRadius: 5.w, 
    //                           height: 34.h, 
    //                           onTop: () {
    //                             Get.toNamed(
    //                               '${AppRouters.COMMON_PAGE}${AppRouters.GOOD_DETAIL_PAGE}',
    //                               arguments: {
    //                                 'goodId': item.id
    //                               }
    //                             );
    //                           }
    //                         ),
    //                       )
    //                     ],
    //                   )
    //                 ],
    //               ),
    //             ))
    //           ],
    //         ),
    //       ), () {
    //         Get.toNamed(
    //           '${AppRouters.COMMON_PAGE}${AppRouters.GOOD_DETAIL_PAGE}',
    //           arguments: {
    //             'goodId': item.id
    //           }
    //         );
    //       }),
    //     );
    //   }
    // );
    // ) 
    return goodsArr.length <= 0 ? SliverList(
      delegate: SliverChildListDelegate([
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(height: 32.h),
            Image.asset(
              'assets/icons/goods_list_def.png',
              width: 221.w,
              height: 118.h,
            ),
            Text(
              '暂无相关数据哦~',
              style: TextStyle(
                color: textSubtitleColor,
                fontSize: 14.sp
              ),
            )
          ],
        ),
      ]),
    ) : SliverList(
      delegate: SliverChildBuilderDelegate((context, index) {
        GoodItem item = goodsArr[index];
        return Container(
          padding: EdgeInsets.symmetric(horizontal: 16.w),
          margin: EdgeInsets.only(bottom: 12.h),
          child: InkWellUtil.shakeProofInkWell(Container(
            padding: EdgeInsets.only(left: 12.w, right: 20.w, top: 16.h, bottom: 16.h),
            decoration: BoxDecoration(
              color: bgWhiteColor,
              borderRadius: BorderRadius.circular(5.w)
            ),
            child: Row(
              children: [
                NetworkImageUtil(
                  url: item.thumbnail ?? '', 
                  width: 97.w, 
                  height: 97.w,
                  borderRadius: 5.w,
                ),
                SizedBox(width: 12.h),
                Expanded(child: Container(
                  constraints: BoxConstraints(
                    minHeight: 97.w
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        item.title ?? '',
                        overflow: TextOverflow.ellipsis,
                        maxLines: 2,
                        style: TextStyle(
                          color: textBlackColor,
                          fontSize: 14.sp
                        ),
                      ),
                      Text.rich(
                        TextSpan(
                          text: '¥',
                          style: TextStyle(
                            color: mainTextColor,
                            fontWeight: FontWeight.bold,
                            fontSize: 14.sp
                          ),
                          children: [
                            TextSpan(
                              text: item.price,
                              style: TextStyle(
                                color: mainTextColor,
                                fontWeight: FontWeight.bold,
                                fontSize: 18.sp
                              ),
                            )
                          ]
                        )
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Container(
                            padding: EdgeInsets.only(bottom: 3.h),
                            child: Text(
                              '+${item.integral}积分',
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                color: mainTextColor,
                                fontSize: 12.sp
                              ),
                            ),
                          ),
                          Container(
                            width: 56.w,
                            height: 34.h,
                            child: ButtonUtil(
                              text: '去下单', 
                              fontSize: 12.sp, 
                              borderRadius: 5.w, 
                              height: 34.h, 
                              onTop: () {
                                Get.toNamed(
                                  '${AppRouters.COMMON_PAGE}${AppRouters.GOOD_DETAIL_PAGE}',
                                  arguments: {
                                    'goodId': item.id
                                  }
                                );
                              }
                            ),
                          )
                        ],
                      )
                    ],
                  ),
                ))
              ],
            ),
          ), () {
            Get.toNamed(
              '${AppRouters.COMMON_PAGE}${AppRouters.GOOD_DETAIL_PAGE}',
              arguments: {
                'goodId': item.id
              }
            );
          }),
        );
      }, childCount: goodsArr.length),
    );
  }
}